/************************************************************************

								Heroes IV
					  Copyright 2002, The 3DO Company

	------------------------------------------------------------------
  						 timed_callback.cpp

	$Header: $

	$NoKeywords: $

 ************************************************************************/

#include "precompiled.h"


#include "timed_callback.h"


t_timed_callback::t_timed_callback()
	: t_idle_processor( 1 )
{

}

t_timed_callback::t_timed_callback( int delay, t_handler callback )
	: t_idle_processor( 0, delay ), m_callback( callback )
{
}

// Cancel callback
void t_timed_callback::cancel()
{
	if ( is_active() )
		suspend_idle_processing();
}

// Setup callback
void t_timed_callback::set( int delay, t_handler callback )
{
	set_delay( delay );
	m_callback = callback;

	if ( !is_active() )
		resume_idle_processing();
}

void t_timed_callback::on_idle()
{
	m_callback();

	if ( is_active() )
		suspend_idle_processing();
}
